﻿using System;
using System.Xml.Serialization;
using EpiNEXT.Services.Fields.Properties;

namespace EpiNEXT.Services.Fields
{
    //[Serializable()]
    public class CommandButtonField : Field
    {
        #region Members
        private string _commandString = String.Empty;
        private ButtonCommands _command = ButtonCommands.Execute;
        #endregion // Members

        #region Constructors
        public CommandButtonField()
            : base()
        {
            PromptFontSize = Constants.DEFAULT_PROMPT_FONT_SIZE;
        }
        #endregion // Constructors

        #region Properties
        [XmlElement]
        public Color ButtonBackgroundColor { get; set; }

        [XmlElement]
        public Color ButtonBorderColor { get; set; }

        [XmlElement("ButtonBorderThickness", typeof(Thickness))]
        public Thickness ButtonBorderThickness { get; set; }

        [XmlElement]
        public string CommandParameter { get; set; }

        [XmlIgnore]
        public ButtonCommands Command
        {
            get
            {
                return this._command;
            }
            set
            {
                if (!Command.Equals(value))
                {
                    this._command = value;

                    switch (Command)
                    {
                        case ButtonCommands.Delete:
                            CommandString = "Delete";
                            break;
                        case ButtonCommands.Execute:
                            CommandString = "Execute";
                            break;
                        case ButtonCommands.New:
                            CommandString = "New";
                            break;
                        case ButtonCommands.Reset:
                            CommandString = "Reset";
                            break;
                        case ButtonCommands.Save:
                            CommandString = "Save";
                            break;
                    }
                }
            }
        }

        [XmlElement("Command")]
        public string CommandString 
        {
            get
            {
                return this._commandString;
            }
            set
            {
                if (!CommandString.Equals(value))
                {
                    this._commandString = value;

                    switch (CommandString)
                    {
                        case "Save":
                            Command = ButtonCommands.Save;
                            break;
                        case "New":
                            Command = ButtonCommands.New;
                            break;
                        case "Delete":
                            Command = ButtonCommands.Delete;
                            break;
                        case "Execute":
                            Command = ButtonCommands.Execute;
                            break;
                    }
                }
            }
        }
        #endregion // Properties
    }
}
